import random
print(random.random())#(0,1)范围之间
print(random.randint(1, 3))#1<=x<=3
print(random.randrange(1, 3))#1<=x<3
print(random.choice([1, 2, 3]))#参数是列表
print(random.sample([1, '23', [4, 5]], 3))#列表元素任意两个组合,第一个参数是列表，第二个是控制数量
print(random.uniform(1, 3))#1<x<3 #1.6320445086604658
#打乱顺序
item=[1,3,5,7,9]
random.shuffle(item)#相当于洗牌,参数可变
print(item)


#应用:随机验证码

def make_code(size=4):
    res = ''
    for i in range(size):
        random_word=chr(random.randint(65, 90))
        random_num=str(random.randint(0, 9))
        random_srt=random.choice([random_word, random_num])
        res+=random_srt
    return res
print(make_code(6))